package alibaba.controller;

import club.xshiwu.springcloud.entities.CommonResult;
import club.xshiwu.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@Slf4j
public class PaymentController {
    @Value("${server.port}")
    private String serverPort;

    public static HashMap<Long, Payment> hashMap = new HashMap<>();

    static {
        hashMap.put(1L, new Payment(1L, "123456"));
        hashMap.put(2L, new Payment(2L, "123456"));
        hashMap.put(3L, new Payment(3L, "123456"));
    }

    /**
     * CommonResult： json封装的实体类
     * @param id 查询id
     * @return
     */
    @GetMapping("/paymentSQL/{id}")
    public CommonResult<Payment> getCommonResult(@PathVariable("id") Long id){
        Payment payment = hashMap.get(id);
        return new CommonResult<>(200, "from mysql ,serverport" + serverPort, payment);
    }
}
